package redis

import (
	gredis "github.com/garyburd/redigo/redis"
)

//BLPOP key [key ...] timeout
//return value
/*
Array reply:specifically:
* A nil multi-bulk when no element could be popped and the timeout expired
* A two-element multi-bulk with the first element being the name of then key
  where an element was popped and the second element being the value of the
  popped element
*/
func (r *RedisPool) BLPop(key interface{}, keysAndTimeout ...interface{}) ([]string, error) {
	return gredis.Strings(r.Do("BLPOP", keysAndTimeout...))
}

//BRPOP key [key ...] timeout
//return value
/*
Array reply:specifically:
* A nil multi-bulk when no element could be popped and the timeout expired
* A two-element multi-bulk with the first element being the name of then key
  where an element was popped and the second element being the value of the
  popped element
*/
func (r *RedisPool) BRPop(key interface{}, keysAndTimeout ...interface{}) ([]string, error) {
	return gredis.Strings(r.Do("BRPOP", keysAndTimeout...))
}

//BRPOPLPUSH source destination timeout
//return value
/*
Bulk string reply: the element being popped from source and pushed to destination.
				   if timeout is reached, a Null reply is returned
*/
func (r *RedisPool) BRPopLPush(source, destination interface{}, timeout int64) ([]string, error) {
	return gredis.Strings(r.Do("BRPOPLPUSH", source, destination, timeout))
}

//LINDEX key index
//return value
/*
Bulk string reply: the requested element, or nil when index is out of range
*/
func (r *RedisPool) LIndex(key, index interface{}) (string, error) {
	return gredis.String(r.Do("LINDEX", key, index))
}

//LINSERT key BEFORE|AFTER pivot value
//return value
/*
Integer reply: the length of the list after the insert operation, or -1
               when the value pivot was not found
*/
//option: BEFORE | AFTER
func (r *RedisPool) LInsert(key interface{}, option string, pivot, value interface{}) (int64, error) {
	return gredis.Int64(r.Do("LINSERT", key, option, pivot, value))
}

//LLEN key
//return value
/*
integer reply: then length of the list at key
*/
func (r *RedisPool) LLen(key interface{}) (int64, error) {
	return gredis.Int64(r.Do("LLEN", key))
}

//LPOP key
//return value
/*
Bulk string reply: the value of the first element, or nil when key does not exist
*/
func (r *RedisPool) LPop(key interface{}) (string, error) {
	return gredis.String(r.Do("LPOP", key))
}

//LPUSH key value [value...]
//return value
/*
Integer reply: the length of the list after the push operations.
*/
func (r *RedisPool) LPush(key interface{}, value ...interface{}) (int64, error) {
	var tmp []interface{}
	tmp = append(tmp, key)
	tmp = append(tmp, value...)
	return gredis.Int64(r.Do("LPUSH", tmp...))
}

//LPUSHX key value
//return value
/*
integer reply: the length of the list after the push operation
*/
func (r *RedisPool) LPushX(key, value interface{}) (int64, error) {
	return gredis.Int64(r.Do("LPUSHX", key, value))
}

//LRANGE key start stop
//return value
/*
Array reply: list of elements in the specified range.
*/
func (r *RedisPool) LRange(key interface{}, start, stop int64) ([]string, error) {
	return gredis.Strings(r.Do("LRANGE", key, start, stop))
}

//LREM key count value
//return value
/*
integer reply: the number of removed elements
*/
func (r *RedisPool) LRem(key, count, value interface{}) (int64, error) {
	return gredis.Int64(r.Do("LREM", key, count, value))
}

//LSET key index value
//return value
/*
simple string reply
*/
func (r *RedisPool) LSet(key, index, value interface{}) (string, error) {
	return gredis.String(r.Do("LSET", key, index, value))
}

//LTRIM key start stop
//return value
/*
simple string reply
*/
func (r *RedisPool) LTRim(key, start, stop interface{}) (string, error) {
	return gredis.String(r.Do("LTRIM", key, start, stop))
}

//RPOP key
//return value
/*
Bulk string reply: the value of the last element,or nil when key does not exist.
*/
func (r *RedisPool) RPop(key interface{}) (string, error) {
	return gredis.String(r.Do("RPOP", key))
}

//RPOPLPUSH source destination
//return value
/*
Bulk string reply: the element being popped and pushed
*/
func (r *RedisPool) RPopLPush(source, destination interface{}) (string, error) {
	return gredis.String(r.Do("RPOPLPUSH", source, destination))
}

//RPUSH key value [value...]
//return value
/*
Integer reply: the length of the list after the push operation
*/
func (r *RedisPool) RPush(key interface{}, value ...interface{}) (int64, error) {
	var tmp []interface{}
	tmp = append(tmp, key)
	tmp = append(tmp, value...)
	return gredis.Int64(r.Do("RPUSH", tmp...))
}

//RPUSHX key value
//return value
/*
Integer reply: the length of the list after the push operation
*/
func (r *RedisPool) RPushX(key, value interface{}) (int64, error) {
	return gredis.Int64(r.Do("RPUSHX", key, value))
}
